{%  extends 'base.html' %}
{% load static %}
{% block content %}
<div class="demoTable">
 搜索项目：
 <div class="layui-inline">
 <input class="layui-input" name="keyword" id="demoReload" autocomplete="off">
 </div>
 <button class="layui-btn" id="jobbtn" data-type="reload">搜索</button>
 <button class="layui-btn" id="addjob" οnclick="selectRole()" type="button" >
 <i class="layui-icon">&#xe608;</i> 添加
 </button>
  <button class="layui-btn" id="delWeb" lay-event="getdeldata" type="button" >
 <i class="layui-icon">&#xe640;</i> 暂停
 </button>
</div>
    
<table class="layui-hide" id="tablea" lay-filter="menu-filter"></table>
{% endblock %}
{% block js %}
<script>
 $("#addjob").click(function () {
    layer.open({
        title: '添加任务',
        type: 1,
        area: ['700px', '600px'],
        content: '<blockquote class="layui-elem-quote layui-text">注意事项: 请填写相关的数据信息! </blockquote>' +
        '<form class="layui-form"> ' +
        '<div class="layui-form-item">' +
        '<div class="layui-inline">' +
        '<label class="layui-form-label">项目名称</label>' +
        '<div class="layui-input-inline">' +
        '<input type="text"  required lay-verify="required" name="project"  class="layui-input" value="" >' +
        '</div></div>' +

        '<div class="layui-inline">' +
        '<label class="layui-form-label">网站名称</label>' +
        '<div class="layui-input-inline">' +
        '<input type="text"  required lay-verify="required" name="name"    class="layui-input" value="" >' +
        '</div></div>' +
        '<div class="layui-inline">' +
        '<label class="layui-form-label">域名</label>' +
        '<div class="layui-input-inline">' +
        '<input type="text"  required lay-verify="required" name="domain"    class="layui-input" value="" >' +
        '</div></div>' +
        '</div>' +
        '<div class="layui-form-item">' +
        '<div class="layui-inline">' +
        '<label class="layui-form-label">命名空间</label>' +
        '<div class="layui-input-inline">' +
        '<input type="text"  required lay-verify="required" name="namespace"  class="layui-input" value="" >' +
        '</div></div>' +
        '</div>' +
        '<div class="layui-form-item" style="width: 621px;">' +
        '<label class="layui-form-label">备注</label>' +
        '<div class="layui-input-block">' +
        '<textarea placeholder="请输入内容" name="siteMark" class="layui-textarea"></textarea>' +
        '</div>' +
        '</form>',
        btnAlign: 'c',
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            var str = $("input[name=isIndividual]").val();
            if (str == "on") {
                str = "1";
            } else {
                str = "0";
            }
            if ($("input[name=project]").val() == null || $("input[name=project]").val() == "") {
                layer.msg('请输入项目名称', {icon: 5, time: 2000, area: '200px', type: 0, anim: 6,}, function () {
                    $("input[name=project]").focus();
                });
                return false;
            } else if ($("input[name=name]").val() == null || $("input[name=name]").val() == "") {
                layer.msg('请输入网站名称', {icon: 5, time: 2000, area: '200px', type: 0, anim: 6,}, function () {
                    $("input[name=name]").focus();
                });
            } else if ($("input[name=domain]").val() == null || $("input[name=domain]").val() == "") {
                layer.msg('请输入域名', {icon: 5, time: 2000, area: '200px', type: 0, anim: 6,}, function () {
                    $("input[name=domain]").focus();
                });
                return false;
            } else if ($("input[name=namespace]").val() == null || $("input[name=namespace]").val() == "") {
                layer.msg('请输入命名空间', {icon: 5, time: 2000, area: '200px', type: 0, anim: 6,}, function () {
                    $("input[name=namespace]").focus();
                });
                return false;
            }
            var formData = {
                project: $("input[name=project]").val(),
                name: $("input[name=name]").val(),
                domain: $("input[name=domain]").val(),
                namespace: $("input[name=namespace]").val(),
                siteMark: $("textarea[name=siteMark]").val()
            };
            console.log(formData);
            $.post('/cmdb/addjob', formData, function (data) {
                //判断是否发送成功
                if (data.code == 200) {
                    layer.msg(data.message);
                    layer.close(index);
                    parent.document.getElementById('my_iframe').contentWindow.location.reload(true);
                } else {
                    layer.msg("保存失败...", {type: 1});
                }
            })
        }, btn2: function (index, layero) {
            layer.msg("取消");
            //return false 开启该代码可禁止点击该按钮关闭
        }, cancel: function () {
            layer.msg("关闭窗口");
            //右上角关闭回调
            //return false 开启该代码可禁止点击该按钮关闭
        },
        success: function () {
            layui.use('form', function () {
                var form = layui.form; //只有执行了这一步，部分表单元素才会修饰成功
         form.render('checkbox');
                form.on('checkbox(istrue)', function (data) {
                    /* if(data.elem.checked){
                     emailConfig['isenterprise']=1;
                     }; //是否被选中，true或者false*/
                });
            });
        }
    });
})

</script>


<script>
 layui.use('table', function() {
 var table = layui.table;
 //方法级渲染
 table.render({
  elem: '#tablea'
  ,toolbar: '#toolbarDemo'
  ,url:'/cmdb/jobjson'
  , cols: [[
  { type: 'checkbox', fixed: 'left'}
   ,{field:'id', title: 'ID',width:20}
  ,{field:'name', title: '任务',width:200}
  ,{field:'image', title: '镜像',width:500}
  ,{field:'plan', title: '计划',width:150}
  ,{field:'cluster', title: '集群',width:150}
  ,{field:'create_time', title: '创建时间',width:200}
  ,{field:'status', title: '任务状态',width:150,sort: true}
  ]]
  , id: 'testReload'
  , page: true
  , height: 600
  ,request: {
  pageName: 'page' //页码的参数名称，默认：page
  ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
  ,statusName:'status'//数据状态的字段名称，默认：code
  ,statusCode:200 //成功的状态码，默认：0
  }
 });


  //头工具栏事件
  table.on('toolbar(tablea)', function(obj){
    var Status = table.checkStatus(obj.config.id);
    switch(obj.event){
      case 'getdeldata':
        var data = Status.data;
        layer.alert(JSON.stringify(data));
      break;
    };
  });

//
 $('#jobbtn').click(function (){
  var inputVal = $('.layui-input').val()
  table.reload('testReload', {
  url: '/cmdb/searchjob'
  ,request: {
   pageName: 'page' //页码的参数名称，默认：page
   ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
  }
  ,where: {
   query : inputVal
  }
  ,page: {
   curr: 1
  }
  });
 })
 })
</script>

{% endblock %}